/**
 * 
 */
package com.github.phoenics.militia.common.exception;


import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;

import com.github.phoenics.militia.common.utils.StatusData;
import org.springframework.http.HttpStatus;


/**
 * @author Phoenics Chow 
 * on 2018年4月10日
 *
 */
//@RestControllerAdvice
public class CommonExceptionHandler {
	private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(CommonExceptionHandler.class);
	/**
	 * 处理自定义异常
	 */
	@ExceptionHandler(CommonException.class)
	@ResponseStatus(HttpStatus.BAD_REQUEST)
	public StatusData handleCommonException(CommonException e){
		return StatusData.error( e.getCode(), e.getMessage());
	}

	@ExceptionHandler(Exception.class)
	@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
	public StatusData handleException(Exception e){
		return StatusData.error();
	}
	@ExceptionHandler(value = {AuthorizedException.class})
	 @ResponseStatus(HttpStatus.UNAUTHORIZED)
	 public StatusData handlerServerError(AuthorizedException ex){
		 return new StatusData(ex.getCode(),ex.getMsg());
	 }
	 @ExceptionHandler(value = {ParamsException.class})
	 @ResponseStatus(HttpStatus.BAD_REQUEST)
	 public StatusData handlerServerError(ParamsException ex){
		 return new StatusData(ex.getCode(),ex.getMsg());
	 }
	
	 @ExceptionHandler(value = {NotFoundException.class})
	 @ResponseStatus(HttpStatus.NOT_FOUND)
	 public StatusData handlerServerError(NotFoundException ex){
		 return new StatusData(ex.getCode(),ex.getMsg());
	 }
}
